package com.example.firstapplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Data extends Activity implements OnClickListener {

	EditText et;
	Button b1, b2;
	TextView tv;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.get);
		initialize();
		
	}

	private void initialize() {
		et = (EditText) findViewById(R.id.eTInput);
		b1 = (Button) findViewById(R.id.bSA);
		b2 = (Button) findViewById(R.id.bSAR);
		tv = (TextView) findViewById(R.id.tVResult);
		b1.setOnClickListener(this);
		b2.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.bSA:
			String bread=et.getText().toString();
			Bundle bundle=new Bundle();
			bundle.putString("key", bread);
			Intent intent=new Intent(Data.this,OpenedClass.class);
			intent.putExtras(bundle);
			startActivity(intent);
			break;
		case R.id.bSAR:
			Intent intent2=new Intent(Data.this, OpenedClass.class);
			startActivityForResult(intent2, 0);
			break;
		}

	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		if(resultCode == RESULT_OK){
			Bundle bundle=data.getExtras();
			tv.setText(bundle.getString("answer"));
		}
	}
}
